﻿using Entitas;
using System.Linq;
using System.Collections.Generic;
class PlayerWeaponSwitchSystem : IExecuteSystem
{
    PlayerContext playerContext;
    public PlayerWeaponSwitchSystem(Contexts contexts)
    {
        playerContext = contexts.player;
    }

    public void Execute()
    {
        if (ServiceManager.InputService.LeftShiftPressed)
        {
            if (playerContext.count == 1)
            {
                var player = playerContext.GetEntities().SingleEntity<PlayerEntity>();
                int value;
                player.inventory.value.TryGetValue(player.equippedWeapon.value, out value);
                var weaponlist=player.inventory.value.Where(x=>x.Key.isWeaponitem==true);
                foreach (var w in weaponlist)
                {
                        if (w.Key == player.equippedWeapon.value)
                            continue;
                        else
                        {
                        IWeapon weapon = w.Key as IWeapon;
                            player.ReplaceEquippedWeapon(weapon);
                            break;
                        }
                    
                }
            }
        }

    }
}


